package com.seed.uaa.web.role;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import com.seed.core.annotation.Col;
import com.seed.core.enumeration.ColumnType;
import com.seed.uaa.web.organization.Organization;
import com.seed.core.annotation.Habtm;
import com.seed.uaa.web.organization.OrganizationRole;
import io.swagger.v3.oas.annotations.media.Schema;

import java.time.LocalDateTime;
import java.util.List;

@Schema(description = "角色")
@Table(value = "uaa_role")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Role {
    @Id
    @Schema(title = "ID")
    private String id;

    @Schema(title = "名称")
    private String name;

    @Schema(title = "访问权限")
    @Col(type = ColumnType.TEXT, length = 2048)
    private String actions;

    @Schema(title = "数据权限")
    @Col(type = ColumnType.TEXT, length = 2048)
    private String datas;

    @Schema(title = "字段权限")
    @Col(type = ColumnType.TEXT, length = 2048)
    private String fields;

    @Schema(title = "所属租户")
    private String tenantId;

    @Schema(title = "创建时间")
    @Column(onInsertValue = "now()")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createdAt;

    @Schema(title = "创建时间")
    @Column(onInsertValue = "now()", onUpdateValue = "now()")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updatedAt;

    @Schema(title = "删除时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime deletedAt;

    @Schema(title = "版本号")
    @Column(version = true)
    private Long version;

    @Schema(title = "组织")
    @Column(ignore = true)
    @Habtm(through = OrganizationRole.class)
    private List<Organization> organizations;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getActions() {
        return actions;
    }

    public void setActions(String actions) {
        this.actions = actions;
    }

    public String getDatas() {
        return datas;
    }

    public void setDatas(String datas) {
        this.datas = datas;
    }

    public String getFields() {
        return fields;
    }

    public void setFields(String fields) {
        this.fields = fields;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }

    public LocalDateTime getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }

    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }

    public LocalDateTime getDeletedAt() {
        return deletedAt;
    }

    public void setDeletedAt(LocalDateTime deletedAt) {
        this.deletedAt = deletedAt;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    public List<Organization> getOrganizations() {
        return organizations;
    }

    public void setOrganizations(List<Organization> organizations) {
        this.organizations = organizations;
    }
}
